﻿<?php
use yii\helpers\Html;
use common\components\widgets\Datetimepicker;
use doumiaoduo\layer\LayerAsset;
use common\components\helpers\Fun;
LayerAsset::register($this);

Datetimepicker::widget(['flag'=>'timepicker']);

?>
    <div class="yx-praise-list-box yx-praise-box yx-radius2 zx-min-height">
        <?= $this->renderFile('@zhtfrontend/views/layouts/toolbar.php'); ?>
            <div id="search-area" class="yx-bgf7f7f7 yx-radius5 zx-mg yx-function2 yx-pr0">
                <?= Html::beginForm(Fun::url(['classhour/index']), 'get', ['enctype' => 'multipart/form-data']) ?>
                <?=\common\components\helpers\Search::dropDownList('mechanic_id',null,array_merge([0=>'请选择'],$listData),['label'=>'机构','promote'=>'请选择机构','class'=>'search diy_select_txt'])?>
                <?= \common\components\helpers\Search::dropDownList('searchDate', null, [0=>'请选择','2017-9' => '2017年9月', '2017-10' => '2017年10月','2017-11' => '2017年11月','2017-12' => '2017年12月','2018-1' => '2018年1月','2018-2' => '2018年2月','2018-3' => '2018年3月','2018-4' => '2018年4月','2018-5' => '2018年5月',],['label'=>'日期','promote'=>'请选择日期','class' => 'search diy_select_txt']); ?>
                <?=\common\components\helpers\Search::dropDownList('searchWay',null,[0=>'请选择',1 => '按月'],['label'=>'按月按日','promote'=>'请选择..','class'=>'search diy_select_txt'])?>
                <?=\common\components\helpers\Search::dropDownList('state',null, [0=>'请选择',2 => '未结算', 1 => '已结算'],['label'=>'状态','promote'=>'请选择..','class'=>'search diy_select_txt'])?>
                <?= \common\components\helpers\Search::submitButton('搜索', ['id'=>'search-handle','class'=>"yx-search yx-radius2"]); ?>
                <?php Html::endForm() ?>
            </div>

    <div class="docs-main zx-mg">
        <table id="tablesaw" class="tablesaw table yx-table1 yx-table3 table-striped with-check" >
        <thead>
        <tr class="yx-bgd2f6ec">
            <th><?=\Yii::t('zhtfrontend','ID');?></th>
            <th><?=\Yii::t('zhtfrontend','商品或课程');?></th>
            <th><?=\Yii::t('zhtfrontend','所属机构');?></th>
            <th><?=\Yii::t('zhtfrontend','学生姓名');?></th>
            <th><?=\Yii::t('zhtfrontend','上课节次');?></th>
            <th><?=\Yii::t('zhtfrontend','上课时间');?></th>
            <th><?=\Yii::t('zhtfrontend','结算状态');?></th>
        </tr>
        </thead>
            <?php if($data):?>
                <?php foreach($data as $item):?>
                    <tr data-id="<?=$item['id']?>">
                        <td><?=$item['id']?></td>
                        <td><?=$item['goods_name']?></td>
                        <td><?=$item['mechanic_name']?></td>
                        <td><?=$item['student_name']?></td>
                        <td><?=$item['class_num']?></td>
                        <td><?=$item['class_date']?></td>
                        <td><?=$item['status']?></td>
                    </tr>
                <?php endforeach;?>
            <?php endif;?>
    </table>
        <div style="text-align: right"><?= common\components\widgets\GoPager::widget(['pagination' => $pages]) ?></div>
    </div>
</div>

<?php
$js = <<<JS
     layer.config({
        extend: ['skin/customskin/style.css']//加载您的扩展样式
    });
    $("a[data-url*=batchupdate]").click(function (e) {
        e.stopPropagation();
        var ids = '';
        $('input[name="checkbox"]:checked').each(function () {
             var val = $(this).val();
            (ids == '') ? ids = val : ids += ',' + val;
        });
        if (ids == '') {
            layer.msg("请先选择需要结算的记录！",{id:'layer-msg',skin: 'layui-msg-customskin',time: 1000});
            return false;
        }
        else {
            var url = $(this).data('url');
            layer.confirm(layout+'<p>已结算的不再结算？</p>', {
                title: '结算',
                area: ['440px', '270px'],
                skin: 'layui-confirm-customskin',
                shift:1,
                id:'layer-iframe',
                btn: ['确定','取消'],
                yes: function(index, layero){
                   $.post(url, {ids: ids,_csrf:yii.getCsrfToken()}, function (data) {
                        if(data == 1){
                            alert('结算成功');
                            window.location.reload();
                        }
                        if(data == 2){
                            alert('此记录已结算');
                            window.location.reload()
                        }
                        if(data == 3){
                           alert('系统错误请重试');
                        }
                    }, 'json');
                  layer.close(index);
                }
          });
        }
    });
JS;
$this->registerJS($js);
?>